package com.zhang.common.exception.handler;

import com.zhang.common.exception.myexception.CaptchaException;
import com.zhang.common.exception.myexception.FileUpException;
import com.zhang.common.util.result.R;
import com.zhang.common.util.result.RUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
@Slf4j
public class FileHandler {

    @ExceptionHandler(value = FileUpException.class)
    public R captchaException(FileUpException e) {
        log.error("图片上传失败", e);
        return RUtils.err(403, "图片上传失败");
    }
    @ExceptionHandler(value = FileSizeLimitExceededException.class)
    public R captchaException(FileSizeLimitExceededException e) {
        log.error("上传失败", e);
        return RUtils.err(403, "文件过大，上传失败！");
    }
}
